package com.common.net.interceptor;

import com.common.net.listener.ProgressListener;
import com.common.net.util.DownLoadResponseBody;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

public class DownLoadInterceptor implements Interceptor {

    private ProgressListener listener;

    public DownLoadInterceptor(ProgressListener listener) {
        this.listener = listener;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());

        return originalResponse.newBuilder()
                .body(new DownLoadResponseBody(originalResponse.body(), listener))
                .build();
    }
}

